package com.museum.controller.depository;


import com.alibaba.fastjson.JSONObject;
import com.museum.base.BaseApiService;
import com.museum.base.BaseResponse;
import com.museum.entity.DO.Depository;
import com.museum.service.DepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Ruiwen
 * @since 2021-01-31
 */
@RestController
@RequestMapping("/depository")
public class DepositoryController extends BaseApiService<JSONObject> {

    @Autowired
    private DepositoryService depositoryService;

    @PostMapping("add")
    public BaseResponse<JSONObject> addDepository(Depository depository) {
        if (!depositoryService.save(depository)) return setResultError("添加出错！");
        return setResultSuccess();
    }

    @DeleteMapping("deleteByID/{id}")
    public BaseResponse<JSONObject> deleteDepository(@PathVariable("id") int id) {
        if (!depositoryService.removeById(id))
            return setResultError("删除出错！");
        return setResultSuccess();
    }

    @GetMapping("selectAll")
    public BaseResponse<JSONObject> getAllDepository() {
        List<Depository> list = depositoryService.list(null);
        JSONObject object = new JSONObject();
        object.put("list", list);
        return setResultSuccess(object);
    }

}

